Ext.namespace("topologic","topologic.vml");

topologic.vml.TopologicFrame=function(parent)
{
   this.parent=parent;
   this.state='NONE';
   this.nodecount=0;
   this.linecount=0;
   this.topologicObject=new topologic.vml.Topologic(this.parent);
   this.rightClick = new Ext.menu.Menu({
            id:'rightClickCont', 
            items: 
            [
              {
               id: 'rMenu1',
               parent:this,
               handler: this.rMenu1Fn,
               text: "新建节点"
              },
              {
               id: 'rMenu2',
               parent:this,
               handler: this.rMenu2Fn,
               text: "新建连接"
              }
            ]
            });      
    this.body=Ext.get(this.parent);
    this.body.parent=this;
    this.body.on("contextmenu",this.rightClickFn);
    
}

topologic.vml.TopologicFrame.prototype.rMenu1Fn=function()
{
  var element=this.parent.topologicObject.createMovaleElement(this.parent.xy[0],this.parent.xy[1],100,50,'item'+this.parent.nodecount,this.parent.nodecount);
  var cmp=Ext.get(element.dom);
  cmp.parent=this.parent;
  cmp.on('click',this.parent.elementClick);
  this.parent.nodecount++;
}

topologic.vml.TopologicFrame.prototype.rMenu2Fn=function()
{
  this.parent.state='START';
  alert("选择起始节点");
}
topologic.vml.TopologicFrame.prototype.rightClickFn=function(e)
{
      e.preventDefault();
      this.parent.xy=e.getXY();
      this.parent.rightClick.showAt(e.getXY());
}
topologic.vml.TopologicFrame.prototype.elementClick=function(e)
{
   if(this.parent.state=='START')
   {
      this.parent.startid=this.dom.id;
      this.parent.state='END';
      alert("选择终止节点");
   }
   else
   if(this.parent.state=='END')
   {
      this.parent.endid=this.dom.id;
      this.parent.topologicObject.createLine(this.parent.startid,this.parent.endid,this.parent.linecount);
      this.parent.linecount++;
      this.parent.state='NONE';
   }
   
   
}